<?php
class M_personil extends CI_Model{
			  
		
	function listPersonil($filter,$limit,$offset){
		$this->db->offset($offset);
		$this->db->limit($limit);
		$sql = "SELECT * FROM m_personil WHERE personil_aktif = 'y'
				";
		if(!empty($filter)){
			$sql .= "AND lower(`personil_nama`)  like '%".addslashes(strtolower($filter))."%'";
		}
		$query = $this->db->query($sql);
		$total = $this->db->select('*')->from('m_personil')->where('personil_aktif','Y')->count_all_results();
		$arr = array();
		foreach($query->result() as $q){
			$arr[] = $q; 
		}
		$final = array(
						'total'   => $total,
						'results' => $arr
					  );
		return json_encode($final);
	}
		
	function save($data){
		$this->db->insert('m_personil',$data);
	}
		
	function edit($data,$personil_id){
		$this->db->where('personil_id',$personil_id);
		$this->db->update('m_personil',$data);  
	}
	function delete($data,$personil_id){
		$this->db->where('personil_id',$personil_id);
		$this->db->update('m_personil',$data);  
	}
}
